<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垃圾收集算法深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(to bottom, #667eea, #764ba2);
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 8px;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #667eea;
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 14px;
            top: 18px;
            width: 2px;
            height: calc(100% - 10px);
            background: #e0e0e0;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .algorithm-card {
            background: white;
            border-radius: 16px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
        }
        
        .pros-cons {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 2rem;
            margin-top: 1.5rem;
        }
        
        .pros, .cons {
            padding: 1.5rem;
            border-radius: 12px;
        }
        
        .pros {
            background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
            border-left: 4px solid #4caf50;
        }
        
        .cons {
            background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
            border-left: 4px solid #f44336;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 tracking-tight">
                    垃圾收集算法
                    <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">深度解析与实践指南</span>
                </h1>
                <p class="text-xl md:text-2xl font-light leading-relaxed opacity-90">
                    探索现代编程语言中的内存管理艺术，理解各种垃圾收集算法的设计哲学与应用场景
                </p>
                <div class="mt-10 flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-memory text-4xl mb-2"></i>
                        <p class="text-sm">内存优化</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-tachometer-alt text-4xl mb-2"></i>
                        <p class="text-sm">性能提升</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-cogs text-4xl mb-2"></i>
                        <p class="text-sm">智能管理</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">每</span>种垃圾收集算法有其特定的设计目标和适用场景。选择合适的垃圾收集算法需要根据应用程序的性能需求、内存使用情况和系统资源等因素综合考虑。本文将深入探讨八种主流的垃圾收集算法，帮助您理解它们的工作原理、优缺点以及最佳应用场景。
                </p>
            </div>
        </div>
    </section>

    <!-- Algorithm Overview Visualization -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">算法关系图谱</h2>
            <div class="mermaid">
                graph TD
                    A[垃圾收集算法] --> B[标记-清除]
                    A --> C[标记-整理]
                    A --> D[复制算法]
                    A --> E[分代收集]
                    A --> F[CMS]
                    A --> G[G1]
                    A --> H[ZGC]
                    A --> I[Shenandoah]
                    
                    B --> J[简单实现]
                    B --> K[内存碎片]
                    
                    C --> L[消除碎片]
                    C --> M[移动开销]
                    
                    D --> N[高效回收]
                    D --> O[内存消耗]
                    
                    E --> P[年轻代]
                    E --> Q[老年代]
                    
                    F --> R[低停顿]
                    G --> S[可预测停顿]
                    H --> T[极低延迟]
                    I --> U[并发回收]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
                    style C fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
                    style D fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
                    style E fill:#fff3e0,stroke:#ff9800,stroke-width:2px
                    style F fill:#e3f2fd,stroke:#2196f3,stroke-width:2px
                    style G fill:#e3f2fd,stroke:#2196f3,stroke-width:2px
                    style H fill:#f3e5f5,stroke:#9c27b0,stroke-width:2px
                    style I fill:#f3e5f5,stroke:#9c27b0,stroke-width:2px
            </div>
        </div>
    </section>

    <!-- Algorithms Detail -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                
                <!-- 标记-清除算法 -->
                <div class="algorithm-card card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title flex items-center">
                        <i class="fas fa-broom feature-icon mr-3"></i>
                        1. 标记-清除算法（Mark-Sweep）
                    </h3>
                    
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">
                        <i class="fas fa-cog text-purple-500 mr-2"></i>工作过程
                    </h4>
                    <div class="space-y-3 mb-6">
                        <div class="timeline-item">
                            <p class="text-gray-700"><strong>标记阶段：</strong>从 GC Roots 开始，标记所有可以访问到的对象。</p>
                        </div>
                        <div class="timeline-item">
                            <p class="text-gray-700"><strong>清除阶段：</strong>遍历整个堆，将未标记的对象（即不可达对象）回收。</p>
                        </div>
                    </div>
                    
                    <div class="pros-cons">
                        <div class="pros">
                            <h5 class="font-semibold text-green-700 mb-3 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>优点
                            </h5>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-angle-right text-green-500 mr-2"></i>简单易实现</li>
                                <li><i class="fas fa-angle-right text-green-500 mr-2"></i>对象的回收较为直接</li>
                            </ul>
                        </div>
                        <div class="cons">
                            <h5 class="font-semibold text-red-700 mb-3 flex items-center">
                                <i class="fas fa-times-circle mr-2"></i>缺点
                            </h5>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-angle-right text-red-500 mr-2"></i><strong>内存碎片：</strong>由于对象回收后留下了空间的"洞"，可能导致内存碎片化</li>
                                <li><i class="fas fa-angle-right text-red-500 mr-2"></i><strong>停顿时间：</strong>整个回收过程会暂停应用程序的执行</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- 标记-整理算法 -->
                <div class="algorithm-card card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title flex items-center">
                        <i class="fas fa-compress-alt feature-icon mr-3"></i>
                        2. 标记-整理算法（Mark-Compact）
                    </h3>
                    
                    <h4 class="text-lg font-semibold mb-3 text-gray-700">
                        <i class="fas fa-cog text-purple-500 mr-2"></i>工作过程
                    </h4>
                    <div class="space-y-3 mb-6">
                        <div class="timeline-item">
                            <p class="text-gray-700"><strong>标记阶段：</strong>从 GC Roots 开始，标记所有可以访问到的对象。</p>
                        </div>
                        <div class="timeline-item">
                            <p class="text-gray-700"><strong>整理阶段：</strong>将标记的对象移动到内存的一端，清除内存中空闲的部分。</p>
                        </div>
                    </div>
                    
                    <div class="pros-cons">
                        <div class="pros">
                            <h5 class="font-semibold text-green-700 mb-3 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>优点
                            </h5>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-angle-right text-green-500 mr-2"></i><strong>消除内存碎片：</strong>通过整理阶段将对象移动到一起，消除了内存碎片</li>
                            </ul>
                        </div>
                        <div class="cons">
                            <h5 class="font-semibold text-red-700 mb-3 flex items-center">
                                <i class="fas fa-times-circle mr-2"></i>缺点
                            </h5>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-angle-right text-red-500 mr-2"></i><strong>移动对象的开销：</strong>需要额外的时间和计算来移动对象</li>
                                <li><i class="fas fa-angle-right text-red-500 mr-2"></i><strong>停顿时间：</strong>整理过程会暂停应用程序的执行</li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- 复制算法 -->
                